{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 500G，一行数据\n",
    "\n",
    "def myreadlines(f, newline):\n",
    "    buf = \"\"\n",
    "    while True:\n",
    "        while newline in buf:\n",
    "            pos = buf.index(newline)\n",
    "            yield buf[:pos]\n",
    "            buf = buf[pos + len(newline):]\n",
    "        chunk = f.read(40960)\n",
    "        if not chunk:\n",
    "            ## 已经读到了文件结尾\n",
    "            yield buf\n",
    "            break\n",
    "        buf += chunk\n",
    "\n",
    "with open('input.txt') as f:\n",
    "    for line in myreadlines(f, \"{|}\"):\n",
    "        print(line)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
